www.gusucode.com > 深度学习(asp)网址导航 v4.0.1 > 深度学习(asp)网址导航 v4.0.1\code\include\Deep.Class.Cache.asp
<% ' '深度学习(asp)缓存类 (ASP Cache Engine) ' Version : 0.0.2 '作者:吕海鹏 www.deepstudy.cn '建立时间:2010-2-4 最后修改时间:2010-2-20 ' ====================================== Class Deep_Cache '对象的声明 Public ReloadTime ' 过期时间(单位为分钟,默认30分钟) Public CacheGroupName '缓存组的名称(当一个站点中有多个缓存组时,则需要为每个缓存组设置不同的名称) Private CacheData Private Sub Class_Initialize() ReloadTime = 30 CacheGroupName = "DeepStudy" End Sub Private Sub Class_Terminate() End Sub '************************************************************ '函数名:SetValue '作 用:设置缓存对象的值 '参 数:MyCacheName ---- 缓存对象的名称 ' vNewValue ----- 要给缓存对象的值 '返回值:True ---- 设置成功,False ---- 设置失败 '************************************************************ Public Function SetValue(MyCacheName, vNewValue) If MyCacheName <> "" Then CacheData = Application(CacheGroupName & "_" & MyCacheName) If IsArray(CacheData) Then CacheData(0) = vNewValue CacheData(1) = Now() Else ReDim CacheData(2) CacheData(0) = vNewValue CacheData(1) = Now() End If Application.Lock Application(CacheGroupName & "_" & MyCacheName) = CacheData Application.UnLock SetValue = True Else SetValue = False End If End Function '************************************************************ '函数名:GetValue '作 用:得到缓存对象的值 '参 数:MyCacheName ---- 缓存对象的名称 '返回值:缓存对象的值 '************************************************************ Public Function GetValue(MyChacheName) If MyChacheName <> "" Then CacheData = Application(CacheGroupName & "_" & MyChacheName) If IsArray(CacheData) Then GetValue = CacheData(0) Else GetValue = "" End If Else GetValue = "" End If End Function '************************************************************ '函数名:CacheIsEmpty '作 用:判断当前缓存是否过期 '参 数:MyCacheName ---- 缓存对象的名称 '返回值:True ---- 已经过期,False ---- 没有过期 '************************************************************ Public Function CacheIsEmpty(MyCacheName) CacheIsEmpty = True CacheData = Application(CacheGroupName & "_" & MyCacheName) If Not IsArray(CacheData) Then Exit Function If Not IsDate(CacheData(1)) Then Exit Function If DateDiff("s", CDate(CacheData(1)), Now()) < 60 * ReloadTime Then CacheIsEmpty = False End If End Function '************************************************************ '过程名:DelCache '作 用:手工删除一个缓存对象 '参 数:MyCacheName ---- 缓存对象的名称 '************************************************************ Public Sub DelCache(MyCacheName) Application.Lock Application.Contents.Remove (CacheGroupName & "_" & MyCacheName) Application.UnLock End Sub '************************************************************ '过程名:DelAllCache '作 用:删除全部缓存对象 '参 数:无 '************************************************************ Public Sub DelAllCache() Dim Cacheobj, strAllCache, CacheList, i For Each Cacheobj In Application.Contents If CStr(Left(Cacheobj, Len(CacheGroupName) + 1)) = CStr(CacheGroupName & "_") Then strAllCache = strAllCache & Cacheobj & "," End If Next CacheList = Split(strAllCache, ",") If UBound(CacheList) > 0 Then For i = 0 To UBound(CacheList) Application.Lock Application.Contents.Remove CacheList(i) Application.UnLock Next End If End Sub End Class %>